package com.laiyima.zhongjiang.linghuilv.demo.home;

import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.laiyima.zhongjiang.linghuilv.demo.R;
import com.laiyima.zhongjiang.linghuilv.demo.util.FixedEditText;

import org.json.JSONObject;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.text.SimpleDateFormat;
import java.util.Date;

import me.imid.swipebacklayout.lib.app.SwipeBackActivity;

public class TaxDetailsActivity extends SwipeBackActivity implements View.OnClickListener {
    private FixedEditText detail_addType,detail_addEm,detail_addBname,detail_addpID,detail_addTaxNo,detail_addBank,detail_addTMoblie,detail_addAmount,detail_addPName,detail_addTCount;
    private FixedEditText detail_addAddress,detail_addPAddress,detail_addAccount,detail_addPMoblie;
    private FixedEditText detail_ctime,detail_check_time,detail_check_res,detail_tracking_num,detail_Remarks;

    private LinearLayout imageView;
    private String TAG="TaxDetailsActivity";
    private int taxDetaicode;
    protected boolean useThemestatusBarColor = false;//是否使用特殊的标题栏背景颜色，android5.0以上可以设置状态栏背景色，如果不使用则使用透明色值
    protected void setStatusBar() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0及以上
            View decorView = getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
            //根据上面设置是否对状态栏单独设置颜色
            if (useThemestatusBarColor) {
                // getWindow().setStatusBarColor(getResources().getColor(R.color.colorTheme));
            } else {
                getWindow().setStatusBarColor(Color.TRANSPARENT);
            }
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4到5.0
            WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes();
            localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ) {//android6.0以后可以对状态栏文字颜色和图标进行修改
            getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tax_details);
        setStatusBar();
        detail_addType= (FixedEditText) findViewById(R.id.detail_tax_invoiceType);
        detail_addType.setLeadText("开票类型");
        detail_addBname= (FixedEditText) findViewById(R.id.detail_tax_billingName);
        detail_addBname.setLeadText("公司名称");
        detail_addAddress= (FixedEditText) findViewById(R.id.detail_tax_taxAddress);
        detail_addAddress.setLeadText("公司地址");
        detail_addEm= (FixedEditText) findViewById(R.id.detail_tax_emailAddress);
        detail_addEm.setLeadText("邮箱地址");
        detail_addpID= (FixedEditText) findViewById(R.id.detail_tax_proxyId);
        detail_addpID.setLeadText("商业ID    ");
        detail_addTaxNo= (FixedEditText) findViewById(R.id.detail_tax_taxNo);
        detail_addTaxNo.setLeadText("税号       ");
        detail_addAccount= (FixedEditText) findViewById(R.id.detail_tax_taxAccount);
        detail_addAccount.setLeadText("对公帐号");
        detail_addBank= (FixedEditText) findViewById(R.id.detail_tax_taxOpenBank);
        detail_addBank.setLeadText("开户行   ");
        detail_addTMoblie= (FixedEditText) findViewById(R.id.detail_tax_taxMobile);
        detail_addTMoblie.setLeadText("手机号   ");
        detail_addAmount= (FixedEditText) findViewById(R.id.detail_tax_taxAmount);
        detail_addAmount.setLeadText("金额       ");
        detail_addPName= (FixedEditText) findViewById(R.id.detail_tax_postName);
        detail_addPName.setLeadText("邮寄姓名");
        detail_addPAddress= (FixedEditText) findViewById(R.id.detail_tax_postAddress);
        detail_addPAddress.setLeadText("邮寄地址");
        detail_addPMoblie= (FixedEditText) findViewById(R.id.detail_tax_postMobile);
        detail_addPMoblie.setLeadText("邮寄电话");
        detail_addTCount= (FixedEditText) findViewById(R.id.detail_tax_taxContent);
        detail_addTCount.setLeadText("开票内容");
        detail_ctime= (FixedEditText) findViewById(R.id.detail_tax_ctime);
        detail_ctime.setLeadText("创建时间");
        detail_check_time= (FixedEditText) findViewById(R.id.detail_tax_check_time);
        detail_check_time.setLeadText("审核时间");
        detail_check_res= (FixedEditText) findViewById(R.id.detail_tax_check_res);
        detail_check_res.setLeadText("审核情况");
        detail_tracking_num= (FixedEditText) findViewById(R.id.detail_tax_tracking_num);
        detail_tracking_num.setLeadText("快递单号");
        detail_Remarks= (FixedEditText) findViewById(R.id.detail_tax_Remarks);
        detail_Remarks.setLeadText("备注       ");


        imageView= (LinearLayout) findViewById(R.id.detail_tax_back);
        imageView.setOnClickListener(this);

        intView();

    }

    private void intView() {
        Intent intent = getIntent();
        String id = intent.getStringExtra("id");
        RequestParams params = new RequestParams("http://zljl.laiima.com/index.php?s=/hjs_api/Invoice/one_invoice");
        //需要带入的参数
        params.addBodyParameter("id", id);
        // params.addBodyParameter("captcha", captcha);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                try {

                    JSONObject jsonObjec = new JSONObject(result);
                    String data = jsonObjec.optString("data", null);
                    Log.e(TAG, "回调成功"+data);
                    if (!TextUtils.isEmpty(data)) {
                        JSONObject jsonObject = new JSONObject(data);
                        String show_invoiceType = jsonObject.optString("invoiceType", "");
                        String show_emailAddress = jsonObject.optString("emailAddress", "");
                        String show_proxyId = jsonObject.optString("proxyId", "");
                        String show_taxOpenBank = jsonObject.optString("taxOpenBank", "");
                        String show_taxAccount = jsonObject.optString("taxAccount", "");
                        String show_taxMobile = jsonObject.optString("taxMobile", "");
                        String show_postMobile = jsonObject.optString("postMobile", "");
                        String show_postName = jsonObject.optString("postName", "");
                        String show_taxAddress = jsonObject.optString("taxAddress", "");
                        String show_postAddress = jsonObject.optString("postAddress", "");
                        String show_taxNo = jsonObject.optString("taxNo", "");
                        String show_billingName = jsonObject.optString("billingName", "");



                        String show_addAmount = jsonObject.optString("taxAmount", "");
                        String show_taxContent = jsonObject.optString("taxContent", "");
                        String show_ctime = jsonObject.optString("ctime", "");
                        String show_check_time = jsonObject.optString("check_time", "");
                        if(show_check_time=="null"){
                            detail_check_time.setText("");
                        }
                        int show_check_res = jsonObject.optInt("check_res", 0);
                        if(show_check_res==1){
                            detail_check_res.setText("审核中");
                        }
                        if(show_check_res==2){
                            detail_check_res.setText("通过");
                            detail_check_res.setTextColor(Color.argb(100,18,108,228));
                        }
                        if(show_check_res==3){
                            detail_check_res.setText("未通过");
                            detail_check_res.setTextColor(Color.RED);
                        }

                        String show_tracking_num = jsonObject.optString("tracking_num", "");
                        if(show_tracking_num=="null"){
                            detail_tracking_num.setText("");
                        }
                        String show_remark = jsonObject.optString("remark", "");
                        if(show_remark=="null"){
                            detail_Remarks.setText("");
                        }






                        detail_addType.setText(show_invoiceType);
                        detail_addEm.setText(show_emailAddress);
                        detail_addBname.setText(show_billingName);
                        detail_addpID.setText(show_proxyId);
                        detail_addTaxNo.setText(show_taxNo);
                        detail_addBank.setText(show_taxOpenBank);
                        detail_addTMoblie.setText(show_taxMobile);
                        detail_addPMoblie.setText(show_postMobile);
                        detail_addPName.setText(show_postName);
                        detail_addAddress.setText(show_taxAddress);
                        detail_addPAddress.setText(show_postAddress);
                        detail_addAccount.setText(show_taxAccount);



                        detail_addAmount.setText(show_addAmount);
                        detail_addTCount.setText(show_taxContent);

                        detail_ctime.setText(stampToDate(show_ctime));




                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (taxDetaicode == 200) {
                }
                if (taxDetaicode == 500) {
                    Toast.makeText(getApplicationContext(), "系统异常", Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

                Log.e(TAG, "Throwable");
            }
            @Override
            public void onCancelled(CancelledException cex) {

            }
            @Override
            public void onFinished() {

            }
        });

    }
    public static String stampToDate(String s){
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date(Long.parseLong(s+"000"));
        res = simpleDateFormat.format(date);
        return res;
    }
    @Override
    public void onClick(View v) {
        int id=v.getId();
        switch (id){
            case R.id.detail_tax_back:
                finish();
                break;
        }
    }
}
